package com.mxx.common.netty.ws;

import com.mxx.common.utils.Strings;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Map;

/**
 * @Auther: Mr. Zeng
 * @Date: 2020/7/15 14:54
 * @Description: Nio请求的方法描述
 */
@Data
@Accessors(chain = true)
public final class DefaultNettyWebsocketMessage implements NettyWebsocketMessage {
    /**
     * 请求方法
     */
    private String method;
    /**
     * 请求信息主体
     */
    private Map meta;

    /**
     * 检查是否未错误请求
     *
     * @return
     */
    @Override
    public boolean failure() {
        return Strings.isEmpty(method);
    }

    /**
     * 匹配请求方法
     *
     * @param method
     * @return
     */
    @Override
    public boolean matcherUrl(String method) {
        return this.method.equals(method);
    }

    @Override
    public String getMethod() {
        return this.method;
    }

    public String getString(String name) {
        return String.valueOf(meta.get(name));
    }

    public Long getLong(String name) {
        return Long.valueOf(getString(name));
    }

    public Float getFloat(String name) {
        return Float.valueOf(getString(name));
    }

    public Integer getInt(String name) {
        return Integer.valueOf(getString(name));
    }

    public Object getObject(String name) {
        return meta.get(name);
    }
}
